package pta;/**
 * @author： li
 * @date： 2022-03-27 20:21
 * @version 1.0
 */
import java.io.InputStreamReader;
import java.util.*;
public class 考试座位号2 {
    public static void main(String[] args) {
    Scanner sc = new Scanner(new InputStreamReader(System.in));
    int n =sc.nextInt();
    String[] zkz = new String[1005];
    int[] pos = new int[1005];
    int[] zzw = new int[1005];
    int b;
    for(int i=1;i<=n;i++){
        zkz[i] =sc.next();
        b =sc.nextInt();
        zzw[i] = sc.nextInt();
        pos[b]=i;
    }
    int m =sc.nextInt();
    while (m>0){
        int x =sc.nextInt();
        System.out.print(zkz[pos[x]]+" "+zzw[pos[x]]+"\n");
        m--;
    }
    }
}
